<?php

/*
 * Action 5$
 *
 * Choose one: Discard 2 Cards; or put a card from your hand on top of your deck; or gain a Copper.
 * Choose one: +3 Coin; or trash your hand; or gain a Duchy.
 */

class Count extends Card implements iAction, iKingdom, iDarkAges {

    public function __construct() {
        parent::__construct("Count", 5);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "Choose one: Discard 2 Cards; or put a card from your hand on top of your deck; or gain a Copper.",
            "Choose one: +3 Coin; or trash your hand; or gain a Duchy.");
    }

    public function play(Game $game, $isRealCard) {


        $options = array(new Option(1, "Discard 2 cards"), new Option(2, "Put a card from your hand on top of deck"), new Option(3, "Gain a Copper"));
        $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Please choose");
        $answer = $output[0];
        if ($answer == "Discard 2 cards") {
            $playHand = $game->getPlayHand();
            if (sizeof($playHand) < 3) {
                $game->discardPlayHand();
                ScreenDisplay::addScreenMessage($game, true, "discard  " . nicePrint($playHand), "discards " . sizeof($playHand) . " cards");
            } else {
                $output = MySocket::GetUserReply($game, Input_ChooseMany, $playHand, 2, 2, null, "Choose cards to discard");
                ScreenDisplay::addScreenMessage($game, true, "discard  " . nicePrint($output), "discards " . sizeof($output) . " cards");
                foreach ($output as $p) {
                    $game->moveCardFromPileToPile($p, PlayHand, DiscardPile);
                }
            }
        } elseif ($answer == "Put a card from your hand on top of deck") {
            $playHand = $game->getPlayHand();
            if (sizeof($playHand) > 0) {
                $playHand = getUniqueCards($playHand);
                if (sizeof($playHand) > 1) {
                    $output = MySocket::GetUserReply($game, Input_ChooseOne, $playHand, 1, 1, null, "Choose a card to return to draw deck");
                    $card_name = $output[0];
                }
                else {
                    $card_name = $playHand[0];
                }

                $card = $game->moveCardFromPileToPile($card_name, PlayHand, DrawPile);
                ScreenDisplay::addScreenMessage($game, false, " and return " . nicePrint($card) . " on your deck", " and returns " . sizeof($card) . " cards back to his deck");
            }
        } elseif ("Gain a Copper") {
            $copper = $game->moveCardFromPileToPile("Copper", BoardCards, DiscardPile);
            ScreenDisplay::addScreenMessage($game, false, " and gain " . nicePrint($copper), " and gains " . ScreenDisplay::$LMSG);
        }

        $options = array(new Option(1, "+3$"), new Option(2, "Trash your hand"), new Option(3, "Gain Duchy"));
        $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Please choose");
        $answer = $output[0];
        if ($answer == "Trash your hand") {
            $playHand = $game->getPlayHand();
            foreach ($playHand as $p) {
                $game->moveCardFromPileToPile($p, PlayHand, Trash);
            }
            ScreenDisplay::addScreenMessage($game, false, ", and trash  " . nicePrint($playHand), ", and trashes " . ScreenDisplay::$LMSG);
        } elseif ($answer == "Gain Duchy") {
            $duchy = $game->moveCardFromPileToPile("Duchy", BoardCards, DiscardPile);
            ScreenDisplay::addScreenMessage($game, false, " and gain " . nicePrint($duchy), " and gains " . ScreenDisplay::$LMSG);
        } else {
            $game->addMoney(new Price(3));
            ScreenDisplay::addScreenMessage($game, false, " and get 3$", " and gets 3$");
        }
        $game->cardActionFinished();
        return true;
    }

}

?>